package com.zb.system.controller;


import com.zb.entity.AccounLoginInfo;
import com.zb.exception.SMSException;
import com.zb.result.Result;
import com.zb.util.PCSmsUtil;
import com.zb.service.ZjCustomerService;
import com.zb.service.ZjEmpService;
import com.zb.utils.TokenUtil;
import com.zb.vo.CustomerInfoUpdateVo;
import com.zb.vo.CustomerRegisterVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 * 商家表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-07-18
 */
@Api(tags = "商家企业类接口")
@RestController
@RequestMapping("/system/customer")
public class ZjCustomerController {
    @Resource
    private ZjCustomerService customerService;
    @Resource
    private ZjEmpService empService;

    @ApiOperation("注册企业")
    @PostMapping("/register")
    public Result register(HttpServletRequest request,  @RequestBody @Valid CustomerRegisterVo registerVo) {
        AccounLoginInfo info = TokenUtil.getAccountLoginInfo(request);
        customerService.register(info, registerVo);
        return Result.success("企业注册成功，请耐心等待客服审核认证！");
    }

    @ApiOperation("获取企业信息")
    @GetMapping("/getCustomerInfo")
    public Result getCustomerInfo(HttpServletRequest request) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取企业信息成功").data("row", customerService.getCustomerInfo(custAccId));
    }

    @ApiOperation("获取企业代码")
    @GetMapping("/getCustomerCode/{code}")
    public Result getCustomerCode(HttpServletRequest request, @PathVariable @ApiParam(value = "短信验证码", required = true) String code) throws SMSException {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        String phone = empService.getSuperAccountByCustAccId(custAccId);
        PCSmsUtil.checkSystemSelectCoode(phone, code);
        return Result.success("获取企业代码成功").data("row", customerService.getCustomerCode(custAccId));
    }

    @ApiOperation("修改企业信息")
    @PutMapping("/updateCustomer")
    public Result updateCustomer(HttpServletRequest request, @RequestBody @Valid CustomerInfoUpdateVo updateVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        customerService.updateCustomer(custAccId, updateVo);
        return Result.success("修改企业信息成功");
    }





}
